package org.idea.spring.bean.listener;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @author linhao
 * @date created in 7:35 下午 2020/10/11
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    /**
     * 会在beanDefinition初始化完成之前进行调用
     * @param beanFactory
     * @throws BeansException
     */
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("ioc容器调用了MyBeanFactoryPostProcessor的postProcessBeanFactory");
        for (String beanDefinitionName : beanFactory.getBeanDefinitionNames()) {
            if("myLog".equals(beanDefinitionName)){
                BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName);
//                beanDefinition.setLazyInit(true);
            }
        }
    }
}
